﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace BusinessInforManagement.DAL
{
    public class DALDatabase
    {
        private string connstr;
        private SqlConnection sqlconn;
        public DALDatabase()
        {
            connstr = WebConfigurationManager.ConnectionStrings["BusinessInformation"].ConnectionString;
            sqlconn = new SqlConnection(connstr);
        }
       
        //查询函数，返回结果类型为DataTable
        public DataTable Query(string sql)
        {
            using(sqlconn)
            {
                sqlconn.Open();
                SqlDataAdapter sda = new SqlDataAdapter(sql, connstr);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                sqlconn.Close();
                return dt;
            }
            
        }
        //添加、修改、删除。
        public int AddEditDelete(string sql)
        {
            using(sqlconn)
            {
                 SqlCommand comm = new SqlCommand(sql, sqlconn);
                 sqlconn.Open();
                 int result = comm.ExecuteNonQuery();
                 sqlconn.Close();
                 return result;
            }
           
        }
    
    }
}